<template>
  <div id="app">
  
    <router-view/>
  </div>
</template>
<script>
// import { userClose } from '@/api/login/index.js'
import {mapMutations } from 'vuex'
export default{
  data() {
    return {
      timer:null,
      banck:'beagin'
    }
  },
  created() {
    const id = sessionStorage.getItem('socketId')
    console.log(id);
     this.$socket.on(`timuserTuiChu`,(data)=>{
      console.log(data);
      this.$alert(`${data.message}，请重新登录`, '警告', {
          confirmButtonText: '确定',
          callback: action => {
            sessionStorage.setItem("userid", '')
            // this.$router.qu
            this.$router.push({
              path: '/',
            })
          }
        });
    })
  //  this.timer=setTimeout(this.xingTiao,10000)
  this.$socket.on('message', (data) => {
      console.log('received message:', data);
    });
    this.$socket.on('one_one_messagesendgo', (data) => {
       const  datas={
        type:data.data.from_userid,
        parmas:{
          type:'other',
          from_userid:data.data.from_userid,
          to_userid:data.data.to_userid,
          messageLx:data.data.messageLx,
          message:data.data.message,
          roomid:data.data.roomid,
          messagetime:data.data.messagetime
        }
       }
      this.updatemessageonetoone(datas)
    });
    this.$socket.on('roomMessage', (data) => {
      console.log(data);
       const datas={
        type:data.params.type,
        parmas:{
          avatar:data.params.data.avatar,
          chatid:'new',
          from_userid:data.params.data.from_userid,
          gender:null,
          message:data.params.data.message,
          messageLx:data.params.data.messageLx,
          messagetime:data.params.data.messagetime,
          roomid:data.params.data.roomid,
          nicheng:null,
          to_userid:null,
          type:data.params.data.type,
          userid:data.params.data.from_userid,
          userxxid:null
        }
       }
      this.updataRoomMessage(datas)
     
    });
  },
  mounted()  {
 
    // this.$socket.on('message',(data)=>{
    //   console.log(data);
    // })
    // window.addEventListener('beforeunload', this.beforeUnload);
  },
   beforeDestroy() {
    // this.timer=null
  },
  destroyed() {
    
  },
  methods: {
    ...mapMutations([
    'updatemessageonetoone',
    'updataRoomMessage'
  ]),
    // beforeUnload(){
    //   const userid=sessionStorage.getItem('userid')
    //   userClose({userid:userid})
    // },
    // xingTiao(){
    //   const id = sessionStorage.getItem('socketId')
    //   const userid=sessionStorage.getItem('userid')
    //   this.$socket.emit('xingTiao',{socketId:id,userid:userid})
    //   this.banck='no'
    //   this.$socket.on(`${id}`,(data)=>{
    //      console.log(data);
    //      this.banck='yes'
    //    })
    //   setTimeout(this.xingTiao,10000)
    // }
  },
}
</script>
<style>
/* #app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

nav {
  padding: 30px;
}

nav a {
  font-weight: bold;
  color: #2c3e50;
}

nav a.router-link-exact-active {
  color: #42b983;
} */
</style>
